package cn.blnp.net.flowable.api.server;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

/**
 * <h3>工作流引擎服务介绍说明</h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/4/29 10:13
 */
@Slf4j
@SpringBootTest
public class ApiServerTest {

    @Resource
    private RepositoryService repositoryService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    private TaskService taskService;
    @Resource
    private HistoryService historyService;
    @Resource
    private ManagementService managementService;
    @Resource
    private IdentityService identityService;
    @Resource
    private FormService formService;
    @Resource
    private DynamicBpmnService dynamicBpmnService;
    @Resource
    private ProcessMigrationService processMigrationService;

    /**
     *  <h3>核心API介绍</h3>
     *  <hr/>
     *  <ol>
     *      <li><b>RepositoryService：</b>提供流程部署和流程定义的操作方法，如流程定义的挂起、激活等。</li>
     *      <li><b>RuntimeService：</b>提供运行时流程实例的操作方法，如流程实例的发起、流程变量的设置等。</li>
     *      <li><b>TaskService：</b>提供运行时流程任务的操作方法，如任务的创建、办理、指派、认领和删除等。</li>
     *      <li><b>HistoryService：</b>提供历史流程数据的操作方法，如历史流程实例、历史变量、历史任务的查询等。</li>
     *      <li><b>ManagementService：</b>提供对工作流引擎进行管理和维护的方法，如数据库表数据、表元数据的查询和执行命令。</li>
     *      <li><b>IdentityService：</b>提供用户或者组的操作方法，如用户的增、删、改、查等。</li>
     *      <li><b>FormService：</b>提供流程表单的操作方法，如表单获取、表单保存等。</li>
     *      <li><b>DynamicBpmnService：</b>提供流程定义的动态修改方法，从而避免重新部署它。</li>
     *      <li><b>ProcessMigrationService：</b>用于支持流程实例的迁移和升级。</li>
     *  </ol>
     *
     *  <p>
     *      <img src="https://free4.yunpng.top/2025/04/29/681037ec17dba.png" />
     *  </p>
     **/

    @Test
    public void test() {
        //加载工作流引擎配置
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration
                //指定配置文件的名称与路径，若与默认名称相同，则不需要指定路径。可以通过：ProcessEngines.getDefaultProcessEngine()
                .createProcessEngineConfigurationFromResource("flowable.cfg.xml");
        //创建ProcessEngine对象
        ProcessEngine processEngine = configuration.buildProcessEngine();

        /**
         *  核心API服务的获取
         **/
        //获取存储服务RepositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //获取运行时服务RuntimeService
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //获取任务服务TaskService
        TaskService taskService = processEngine.getTaskService();
        //获取历史服务HistoryService
        HistoryService historyService = processEngine.getHistoryService();
        //获取表单服务FormService
        FormService formService= processEngine.getFormService();
        //获取身份服务IdentityService
        IdentityService identityService = processEngine.getIdentityService();
        //获取管理服务ManagementService
        ManagementService managementService = processEngine.getManagementService();
        //获取动态BPMN服务DynamicBpmnService
        DynamicBpmnService dynamicBpmnService = processEngine.getDynamicBpmnService();
        //获取流程迁移服务ProcessMigrationService
        ProcessMigrationService processMigrationService = processEngine.getProcessMigrationService();
    }
}
